<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>

    <!-- ✅ type is set to `module` ✅ -->
    <script type="module" src="./nuclear-api.js"></script>
    <script type="module">
        import {loginAsTestMerchant, generateTenConsumeCodesAndUseFirstOne, getConsumeCode} from "./nuclear-api.js";

        try {
            var loginResult = await loginAsTestMerchant();
            var usedConsumeCodeInfo = await generateTenConsumeCodesAndUseFirstOne(loginResult.merchantId);
            console.log("The used code info is:");
            console.log(usedConsumeCodeInfo);

            var consumeCodeDetails = await getConsumeCode(
                usedConsumeCodeInfo.merchantId,
                usedConsumeCodeInfo.productId,
                usedConsumeCodeInfo.userId,
                usedConsumeCodeInfo.benefitsCardNo,
                usedConsumeCodeInfo.consumeCode
            );

            console.log("The consume code is: ");
            console.log(consumeCodeDetails);
        }
        catch (e) {
            console.log(e);
        }
    </script>
  </body>
</html>
